package com.amigo.online.provider.manager.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.amigo.online.common.base.controller.BaseController;
import com.amigo.online.common.core.response.Response;
import com.amigo.online.provider.manager.model.entity.FollowTbl;
import com.amigo.online.provider.manager.model.entity.User;
import com.amigo.online.provider.manager.service.FollowTblService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@RestController
@RequestMapping(value = "/followTbl", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class FollowTblController extends BaseController {
    @Resource
    private FollowTblService followTblService;

    /**
     * 查询我关注的用户
     *
     * @param followTbl
     * @return
     */
    @PostMapping(value = "/getTargetUserList")
    public ResponseEntity<Response> getTargetUserList(@RequestBody FollowTbl followTbl) {
        JSONObject result = new JSONObject();
        // 分页语句
        Page<Object> page = PageHelper.startPage(followTbl.getPageNo(), 10);
        List<FollowTbl> targetUserList = followTblService.findTargetUser(followTbl);
        result.put("targetUserList", targetUserList);
        result.put("pagetotal", page.getTotal());
        return success(result);
    }

    /**
     * 粉丝查询
     *
     * @param followTbl
     * @return
     */
    @PostMapping(value = "/getFansUserList")
    public ResponseEntity<Response> getFansUserList(@RequestBody FollowTbl followTbl) {
        JSONObject result = new JSONObject();
        // 分页语句
        Page<Object> page = PageHelper.startPage(followTbl.getPageNo(), 10);
        List<FollowTbl> fansUserList = followTblService.findFansUser(followTbl);
        result.put("fansUserList", fansUserList);
        result.put("pagetotal", page.getTotal());
        return success(result);
    }

    /**
     * 好友查询
     *
     * @param followTbl
     * @return
     */
    @PostMapping(value = "/getFriendUser")
    public ResponseEntity<Response> getFriendUser(@RequestBody FollowTbl followTbl) {
        JSONObject result = new JSONObject();
        // 分页语句
        Page<Object> page = PageHelper.startPage(followTbl.getPageNo(), 10);
        List<User> friendUserList = followTblService.findFriendUser(followTbl);
        result.put("friendUserList", friendUserList);
        result.put("pagetotal", page.getTotal());
        return success(result);
    }

}
